﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Drawing;

namespace HA.Data
{

    //被新类所替换

   // [Serializable]
   //public class DOContourOption
   // {

   //     public DOContourOption()
   //     {

   //         this._contourGeneral = new DOContourGeneral();

   //         this._contourGridLayers = new DOContourGridLayers();
        
        
   //     }


   //     DOContourGeneral _contourGeneral;
   //     /// <summary>
   //     /// ContourOptions中的General设置
   //     /// </summary>
   //     public DOContourGeneral ContourGeneral
   //     {
   //         get { return _contourGeneral; }
          
   //     }



   //     DOContourGridLayers _contourGridLayers;
   //     /// <summary>
   //     /// ContourOptions中的Gridlayers设置
   //     /// </summary>
   //     public DOContourGridLayers ContourGridLayers
   //     {
   //         get { return _contourGridLayers; }
          
   //     }





   // }


    [Serializable]
    public class DOContourOptionV2:ICloneable
    {


        public DOContourOptionV2()
        {


            //取得


            this._contourColors = new List<Color>();

            this._contourColors.Add(Color.Blue);

            this._contourColors.Add(Color.LightBlue);

            this._contourColors.Add(Color.LightGreen);

           

            this._contourColors.Add(Color.Yellow);

            this._contourColors.Add(Color.Red);
           
          


          


        }


        [field:NonSerialized]
        public event EventHandler ContourLinesChanged;

        #region 属性部分


        ContourDisplayType _contourDisplayType = ContourDisplayType.Linear;
        /// <summary>
        /// ContourOptions中的Contour选项控制
        /// </summary>
        public ContourDisplayType ContourType
        {
            get { return _contourDisplayType; }
            set { _contourDisplayType = value; }
        }



        ContourColorMode _colorMode;

        public ContourColorMode ColorMode
        {
            get { return _colorMode; }
            set { _colorMode = value; }
        }


        bool _isSpecifyRange = false;

        public bool IsSpecifyRange
        {
            get { return _isSpecifyRange; }
            set { _isSpecifyRange = value; }
        }



        double _spRangeMin = 0;

        public double SpRangeMin
        {
            get { return _spRangeMin; }
            set { _spRangeMin = value; }
        }





        double _spRangeMax = 1;

        public double SpRangeMax
        {
            get { return _spRangeMax; }
            set { _spRangeMax = value; }
        }



        double _dsMin = 0;

        public double DsMin
        {
            get { return _dsMin; }
            set { _dsMin = value; }
        }

        double _dsMax = 1;

        public double DsMax
        {
            get { return _dsMax; }
            set { _dsMax = value; }
        }



        double  dataRange=1;
        /// <summary>
        /// 数据间距
        /// </summary>
        public double  DataRange
        {
            get { return dataRange; }
            set { dataRange = value; }
        }

        int dataCount = 15;
         /// <summary>
        /// 个数
        /// </summary>
        public int DataCount
        {
            get { return dataCount; }
            set { dataCount = value; }
        }
      
       
        bool _isSpecifyPrecision = false;

        public bool IsSpecifyPrecision
        {
            get { return _isSpecifyPrecision; }
            set { _isSpecifyPrecision = value; }
        }


        int _precision=1;

        public int Precision
        {
            get { return _precision; }
            set { _precision = value;
            if (_precision < 0)
            {
                _precision = 1;
            }
            if (_precision > 15)
            {
                _precision = 1;
            }
            }
        }


        int _noSpecifyPrecisionDecimalNum = 15;
        /// <summary>
        /// 小数点位数  包括等值线值，等值线标注，图例文本等等
        /// 约定：
        /// 不使用统一小数点位数时：读取该字段
        /// 使用统一小数点位数时：读取DecimalDigitNum
        /// </summary>
        public int NoSpecifyPrecisionDecimalNum
        {
            get { return _noSpecifyPrecisionDecimalNum; }
            set
            {

                if (_noSpecifyPrecisionDecimalNum == value)
                {
                    return;
                }
                else
                {
                    _noSpecifyPrecisionDecimalNum = value;
                    //this.isNeedUpdateData = true;
                }

                if (_noSpecifyPrecisionDecimalNum < 0)
                {
                    _noSpecifyPrecisionDecimalNum = 1;
                }
                if (_noSpecifyPrecisionDecimalNum > 15)
                {
                    _noSpecifyPrecisionDecimalNum = 1;
                }
            }
        }



        bool _isShowLegend=false;

        public bool IsShowLegend
        {
            get { return _isShowLegend; }
            set { _isShowLegend = value; }
        }




        double _transparency=0;

        /// <summary>
        /// 透明度
        /// </summary>
        public double Transparency
        {
            get { return _transparency; }
            set { _transparency = value; }
        }





        List<LinearContourColorValue> _contourlines = new List<LinearContourColorValue>();


        /// <summary>
        /// 存储的等值线值
        /// </summary>
        public List<LinearContourColorValue> ContourLines
        {
            get { return _contourlines; }

        }






        ContourInterval _contourInterval = ContourInterval.NumberOfContours;

        public ContourInterval ContourInterval
        {
            get { return _contourInterval; }
            set { _contourInterval = value; }
        }



        List<System.Drawing.Color> _contourColors;
        /// <summary>
        /// 颜色集合
        /// </summary>
        public List<System.Drawing.Color> ContourColors
        {
            get { return _contourColors; }
            set
            {

                _contourColors = value;

            }

        } 





        #endregion



        #region 方法部分


        public  double Min
        {
            get {

                if (this._isSpecifyRange)
                {
                    return this._spRangeMin;

                }

                else
                {
                    return this._dsMin;
                }
            
            
            }

 
        }


        public double Max

        {

            get
            {

                if (this._isSpecifyRange)
                {
                    return this._spRangeMax;

                }

                else
                {
                    return this._dsMax;
                }
                
            }
 

        }





        /// <summary>
        /// 用于对话框等的改变事件
        /// </summary>
        /// <param name="lines"></param>
        public void ResetContourLines(List<LinearContourColorValue> lines)
        {

            this._contourlines.Clear();

            this._contourlines.AddRange(lines);


            if (this.ContourLinesChanged != null)
            {
                this.ContourLinesChanged(this, new EventArgs());

            }



        }





     
   



        /// <summary>
        /// 计算对应的等值线值以及颜色
        /// </summary>
        public void BuildContourlines()
        {
            if (this.dataCount <= 0)
            {
                this.dataCount = 1;
            }
            if (this.dataRange <= 0)
            {
                this.dataRange = 1;
            }

            ContourBuildOption cb = new ContourBuildOption(this.Min, this.Max, this._contourColors);
            List<LinearContourColorValue> lines = new List<LinearContourColorValue>();
            if (this._contourInterval == ContourInterval.NumberOfContours)
            {
              lines = cb.BuildCountourLineWithCount(this.DataCount, this.Precision, this.IsSpecifyPrecision,ref this._noSpecifyPrecisionDecimalNum);
            }
            else if (this._contourInterval == ContourInterval.SpecifiedInterval)
            {
                lines = cb.BuildContourLineWithDistance(this.DataRange, this.Precision, this.IsSpecifyPrecision,ref this._noSpecifyPrecisionDecimalNum);
            }
            else if (this._contourInterval == ContourInterval.SpecifiedValues)
            {
                //此处少自定义生成方案
            }

       

            this._contourlines.Clear();

            this._contourlines.AddRange(lines);



            


        }



        /// <summary>
        /// 用于对话框编辑了所有的属性
        /// </summary>
        /// <param name="doContour"></param>
        public void ReSetContourOption(DOContourOptionV2 doContour)
        {

            if (this!=doContour)
            {
                this._colorMode = doContour._colorMode;
                this._contourColors = doContour._contourColors;
                this._contourDisplayType = doContour._contourDisplayType;
                this._contourInterval = doContour._contourInterval;
                this._contourlines = doContour._contourlines;
                this._dsMax = doContour._dsMax;
                this._dsMin = doContour._dsMin;
                this._isShowLegend = doContour._isShowLegend;
                this._isSpecifyPrecision = doContour._isSpecifyPrecision;
                this._isSpecifyRange = doContour._isSpecifyRange;
                this._precision = doContour._precision;
                this._spRangeMax = doContour._spRangeMax;
                this._spRangeMin = doContour._spRangeMin;
                this._transparency = doContour._transparency;
                this.dataRange = doContour.dataRange;
                if (this._contourlines != null)
                {
                    this.dataCount = this._contourlines.Count;
                }
                else
                {
                    this.dataCount = doContour.dataCount;
                }
                


                if (this.ContourLinesChanged != null)
                {
                    this.ContourLinesChanged(this, new EventArgs());

                }

               
            }


            //需要判断和旧的等值线是否相等
 

        }



     


        #endregion


        public static bool operator ==(DOContourOptionV2 sp1, DOContourOptionV2 sp2)
        {
            // check for both null (cast to object or recursive loop)
            if ((object)sp1 == null && (object)sp2 == null)
            {
                return true;
            }

            // check for either of them == to null
            if ((object)sp1 == null || (object)sp2 == null)
            {
                return false;
            }

            if (sp1._colorMode==sp2._colorMode)
            {
                return false;
            }
            if (sp1._contourColors == sp2._contourColors)
            {
                return false;
            }
            if (sp1._contourDisplayType == sp2._contourDisplayType)
            {
                return false;
            }
            if (sp1._contourInterval == sp2._contourInterval)
            {
                return false;
            }
            if (sp1._contourlines == sp2._contourlines)
            {
                return false;
            }
            if (sp1._dsMax == sp2._dsMax)
            {
                return false;
            }
            if (sp1._dsMin == sp2._dsMin)
            {
                return false;
            }
            if (sp1._isShowLegend == sp2._isShowLegend)
            {
                return false;
            }
            if (sp1._isSpecifyPrecision == sp2._isSpecifyPrecision)
            {
                return false;
            }
            if (sp1._isSpecifyRange == sp2._isSpecifyRange)
            {
                return false;
            }
            if (sp1._precision == sp2._precision)
            {
                return false;
            }
            if (sp1._spRangeMax == sp2._spRangeMax)
            {
                return false;
            }
            if (sp1._spRangeMin == sp2._spRangeMin)
            {
                return false;
            }
            if (sp1._transparency == sp2._transparency)
            {
                return false;
            }
            return true;
        
        }


        public static bool operator !=(DOContourOptionV2 sp1, DOContourOptionV2 sp2)
        {
            return (!(sp1 == sp2));

        }


        #region ICloneable 成员

        public object Clone()
        {
           DOContourOptionV2 option=  (DOContourOptionV2)this.MemberwiseClone();
           List<System.Drawing.Color> color = new List<Color>();
           color.AddRange(this.ContourColors);
          
           option.ContourColors=new List<Color> ();
           option.ContourColors = color;
           return option;


        }





        #endregion
    }



}
